<?php

namespace User\Form\Fieldset;

use User\Model\Entity\User;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;

class ChangePasswordFieldset extends Fieldset implements InputFilterProviderInterface {
    public function __construct() {
    	parent::__construct('user');
        $this->setHydrator(new ClassMethodsHydrator(false))
             ->setObject(new User());

        $this->add(array(
        	'type' => 'Zend\Form\Element\Password',
            'name' => 'password',
        	'attributes' => array(
       			'class' => 'form-control',
            ),
            'options' => array(
                'label' => 'Current Password',
                'label_attributes' => array( 
            		'class' => 'col-lg-2 control-label', 
        		),
            ),
        ));
        
        $this->add(array(
        	'type' => 'Zend\Form\Element\Password',
            'name' => 'newPassword',
        	'attributes' => array(
       			'class' => 'form-control',
            ),
            'options' => array(
                'label' => 'New Password',
                'label_attributes' => array( 
            		'class' => 'col-lg-2 control-label', 
        		),
            ),
        ));
        
        $this->add(array(
        	'type' => 'Zend\Form\Element\Password',
            'name' => 'newPasswordVerify',
        	'attributes' => array(
       			'class' => 'form-control',
            ),
            'options' => array(
                'label' => 'Confirm New Password',
                'label_attributes' => array( 
            		'class' => 'col-lg-2 control-label', 
        		),
            ),
        ));
    }

    /**
     * Should return an array specification compatible with
     * {@link Zend\InputFilter\Factory::createInputFilter()}.
     *
     * @return array
     */
    public function getInputFilterSpecification() {
        return array(
            'password' => array(
                'required' => true,
       			'filters'  => array(
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                	array(
                        'name' => 'StringLength',
                        'options' => array(
                            'min' => 6,
                            'max' => 20,
                        ),
                    ),
                ),
            ),
            'newPassword' => array(
                'required' => true,
            	'filters'  => array(
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                	array(
                        'name' => 'StringLength',
                        'options' => array(
                            'min' => 6,
                            'max' => 20,
                        ),
                    ),
                ),
            ),
            'newPasswordVerify' => array(
                'required' => true,
            	'filters'  => array(
                    array('name' => 'StringTrim'),
                ),
                'validators' => array(
                	array(
                        'name' => 'StringLength',
                        'options' => array(
                            'min' => 6,
                            'max' => 20,
                        ),
                    ),
                	array(
                        'name' => 'Identical',
                        'options' => array(
                            'token' => 'newPassword',
                        ),
                    ),
                ),
            ),
        );
    }
}